package cfca.paperless.client.servlet._4_manager._4_05_DownloadSeal;

import cfca.paperless.client.servlet.PaperlessConfig;
import cfca.paperless.client.servlet.PaperlessManagerClient;
import cfca.paperless.client.util.IoUtil;
import cfca.paperless.client.util.StringUtil;
import cfca.sadk.util.Base64;

/**
 * @Description 下载印章接口（测试用例）
 * @Author dell
 * @Date 2016-5-13
 * @CodeReviewer TODO
 */
public class DownloadSealTest01 {

    public static void main(String[] args) throws Exception {
        try {
            PaperlessManagerClient clientBean = new PaperlessManagerClient(PaperlessConfig.managerUrl, 10000, 60000);// 无纸化管理接口的访问URL
            
            String sealCode = "yz201804457754378";
            String sealPassword = "cfca1234";
            
            StringBuffer requestXml = new StringBuffer("<Request>");
            requestXml.append("<SealCode>").append(sealCode).append("</SealCode>");
            requestXml.append("<SealPassword>").append(sealPassword).append("</SealPassword>");
            requestXml.append("</Request>");
           
            // 操作员编码或者机构号
            String operatorCode = PaperlessConfig.operatorCode;
            // 机构编码
            String channelCode = PaperlessConfig.channelCode;

            // 获取签章信息
            String result = clientBean.downloadSeal(requestXml.toString(), operatorCode, channelCode);

            String code = StringUtil.getNodeText(result, "Code");

            if ("200".equals(code)) {
                System.out.println("OK:downloadSeal");
                System.out.println(result);
                String publicCertString = StringUtil.getNodeText(result, "PublicCert");
                byte[] publicCertData = Base64.decode(publicCertString);
                IoUtil.write("./TestData/output/SealCert.cer", publicCertData);
                String sealImageString = StringUtil.getNodeText(result, "SealImage");
                byte[] sealImageData = Base64.decode(sealImageString);
                IoUtil.write("./TestData/output/SealImage.png", sealImageData);
            } else {
                System.out.println("NG:downloadSeal");
                // 处理结果为异常，打印出错误码和错误信息
                System.out.println(result);
            }
            

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
